//define(function(require,exports,module){
    angular.module('mineApp')
         .controller('DetailCtrl',["$scope","$http","$location","Upload", function ($scope,$http,$location,Upload) {
            //head
            $scope.next = '<a class="s-red" href="javascript:;">完成</a>';

            //取得当前用户数据
            $scope.user={};
            $http.get(hpfbase.url+"/u/user/get-user-info.jhtm")
                .success(function(ret){
                     if(ret.statusCode==1){
                         $scope.user=ret.data;
                     };
                });
            /**
             * 头像上传
             **/
            $scope.$watch('files', function () {
                $scope.upload($scope.files);
            });
            $scope.upload = function (files) {
                if (files && files.length) {
                    for (var i = 0; i < files.length; i++) {
                        var file = files[i];
                        Upload.upload({
                            url: hpfbase.url+'upload/url',
                            fields: {'username': $scope.username},
                            file: file
                        }).progress(function (evt) {
                            var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
                            console.log('progress: ' + progressPercentage + '% ' + evt.config.file.name);
                        }).success(function (data, status, headers, config) {
                            //$scope.user.headImg =config.file.name;
                            console.log('file ' + config.file.name + 'uploaded. Response: ' + data);
                        });
                    }
                }
            };
            /*表单提交*/
            var transformRequest = function(obj) {
                var str = [];
                for(var p in obj)
                    str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                return str.join("&");
            }
            $scope.detail = function(){
                var data = transformRequest($scope.user);
                $http.post(hpfbase.url+"/u/user/get-user-info.jhtm",
                    data,
                        {headers: {
                            'Content-Type': "application/x-www-form-urlencoded;charset=utf-8"
                        }}
                    )
                    .success(function(ret){
                        if(ret.statusCode==1){
                            $location.path("/");
                        };
                    });
            }
        }]);
//})